﻿using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Data;
using EDMDesigner.Designer.Controls.Util;

namespace EDMDesigner.Designer.Controls.Mapping
{
    public abstract class TableMapping : UserControl
    {
        protected abstract void SetTablesValues(IEnumerable<Business.SSDL.EntityType.EntityType> tables);

        private IEnumerable<Business.SSDL.EntityType.EntityType> _tables;
        public IEnumerable<Business.SSDL.EntityType.EntityType> Tables
        {
            get { return _tables; }
            set
            {
                _tables = value;
                SetTablesValues(value);
            }
        }

        public virtual EDMDesigner.Business.SSDL.EntityType.EntityType Table { get; set; }

        private ComboBoxSelectedValueBindingWithNull<Business.SSDL.EntityType.EntityType> _tableComboBoxValue;
        public ComboBoxSelectedValueBindingWithNull<Business.SSDL.EntityType.EntityType> TableComboBoxValue
        {
            get
            {
                if (_tableComboBoxValue == null)
                    _tableComboBoxValue = new ComboBoxSelectedValueBindingWithNull<Business.SSDL.EntityType.EntityType>(null, table => TableValueChange(table));
                return _tableComboBoxValue;
            }
        }

        protected virtual void TableValueChange(Business.SSDL.EntityType.EntityType table)
        {
            Table = table;
        }
    }
}
